package com.example.moudlec.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.moudlec.dto.ConDto;
import com.example.moudlec.mapper.Quality_controlDtMapper;
import com.example.moudlec.mapper.Quality_controlMapper;
import com.example.moudlec.service.Quality_controlService;
import com.mycloud.api.pojo.Quality_control;
import com.mycloud.api.pojo.Quality_controlDt;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@SuppressWarnings("all")
@Service
public class Quality_controlServiceImpl implements Quality_controlService {
    @Autowired
    Quality_controlMapper mapper;

    @Autowired
    Quality_controlDtMapper dtmapper;

    @Override
    public Integer selConRow(Long orderId, Integer productId) {
        return mapper.selConRow(orderId, productId);
    }

    @Override
    public void updaCargo(Long orderId, Integer productId) {
        mapper.updaCargo(orderId, productId);
    }

    @Override
    public void addQc(Quality_control quality_control) {
        mapper.addQc(quality_control);
    }

    @Override
    public Long selMaxId(Long orderId, Integer productId) {
        return mapper.selMaxId(orderId, productId);
    }

    @Override
    public IPage<Quality_control> selController(Long pageNum, Long pageSize) {
        Page<Quality_control> page = new Page<Quality_control>(pageNum, pageSize, true);
        return mapper.selController(page);
    }

    @Override
    public void updconDt(ConDto conDto) {
        Quality_control con = conDto.getCon();
        List<Quality_controlDt> dt = conDto.getDt();
        Quality_controlDt dts = dt.get(0);
        mapper.updCon(con);
        dtmapper.updconDt(dts);
        dtmapper.updaExStuats(dts.getOrderId());
    }

    @Override
    public IPage<Quality_control> selcheckdt(Long pageNum, Long pageSize) {
        Page<Quality_control> page = new Page<Quality_control>(pageNum, pageSize, true);
        return mapper.checkzhiJian(page);
    }

    @Override
    public void updCon2(ConDto conDto) {
        List<Quality_controlDt> dt = conDto.getDt();
        Quality_controlDt dts = dt.get(0);
        dtmapper.updconDts(dts);
        Long orderId = dts.getOrderId();
        Long exeorderdtId = dts.getExeorderdtId();
        Integer productId = dts.getProductId();
        Integer quantityNum = dts.getQuantityNum();
        Integer count = dtmapper.selCountDt(exeorderdtId, orderId, productId);
        String tag="等待放货";
        if (quantityNum==count) {
//            tag="";
//            if(){
//                tag="质检完成";
//            }
        }
        Quality_control con = conDto.getCon();
        con.setQuantityNum(quantityNum);
        con.setCheckTag(tag);
        mapper.updCon2(con);
    }


}
